﻿using System;
using System.Collections.Generic;
using System.Text;
using Langexplr.Abc;
using System.IO;

namespace AbcLibrary.Tests
{
    public class BaseClassTestFixture
    {
        protected static List<AvmClass> LoadClass(BinaryReader reader)
        {

            AbcFile file = AbcFile.ReadFrom(reader);
            List<AvmClass> classes = new List<AvmClass>();
            for (int i = 0; i < file.Classes.Length; i++)
            {
                classes.Add(
                    AvmClass.Create((AbcClassInfo)file.Classes.GetValue(i),
                                    (AbcInstanceInfo)file.Instances.GetValue(i),
                                    file.Methods,
                                    file.MethodBodies,
                                    file.ConstantPool,new QualifiedName[]{}));
            }
            return classes;
        }
        protected static AbcFileInstruction[] GetInitMethodInstructions(BinaryReader reader)
        {

            AbcFile file = AbcFile.ReadFrom(reader);
            AvmScript script =
                AvmScript.Create(file.Scripts[0],
                             file.Methods,
                             file.MethodBodies,
                             file.Instances,
                             file.ConstantPool,new QualifiedName[]{});
            return script.InitMethod.Body.Value.Instructions;
        }


    }
}
